cmake_minimum_required(VERSION 3.10)
# Project name
project(UHFReader_RD905UW)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_INSTALL_PREFIX /usr/local)

find_package(Threads)
find_package (PkgConfig REQUIRED)
pkg_check_modules (GTK3 REQUIRED gtk+-3.0)
add_definitions (${GTK3_CFLAGS_OTHER})

set(CMAKE_C_FLAGS "-g -static-libgcc -static-libstdc++")
set(CMAKE_CXX_FLAGS "-g -static-libgcc -static-libstdc++")

set(IncludePath ${CMAKE_CURRENT_SOURCE_DIR}/)
set(SrcPath "${CMAKE_CURRENT_SOURCE_DIR}/")

# Sources
include_directories(${IncludePath})
include_directories (${GTK3_INCLUDE_DIRS})

#link_directories (${GTK3_LIBRARY_DIRS})
if(APPLE)
	find_library(IOKIT_LIBRARY IOKit)
	find_library(FOUNDATION_LIBRARY Foundation)
endif()

## Sources
set(serial_SRCS
	serial/src/serial.cc
	serial/include/serial/serial.h
	serial/include/serial/v8stdint.h
)
if(APPLE)
	# If OSX
	list(APPEND serial_SRCS serial/src/impl/unix.cc)
	list(APPEND serial_SRCS serial/src/impl/list_ports/list_ports_osx.cc)
elseif(UNIX)
	# If unix
	list(APPEND serial_SRCS serial/src/impl/unix.cc)
	list(APPEND serial_SRCS serial/src/impl/list_ports/list_ports_linux.cc)
else()
	# If windows
	list(APPEND serial_SRCS serial/src/impl/win.cc)
	list(APPEND serial_SRCS serial/src/impl/list_ports/list_ports_win.cc)
endif()

## Add serial library
add_library(serial ${serial_SRCS})
if(APPLE)
	target_link_libraries(serial ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
	target_link_libraries(serial rt pthread)
else()
	target_link_libraries(serial setupapi)
endif()

## Include headers
include_directories(serial/include)

file(GLOB SOURCES_gtkUI "${SrcPath}/*.cpp")

# Executable
add_executable(${PROJECT_NAME} ${SOURCES_gtkUI})
target_link_libraries(${PROJECT_NAME} pthread)
target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES})
target_link_libraries(${PROJECT_NAME} serial)

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/builder.ui DESTINATION bin)
